﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace MartinRL.ProjectEuler.Sequences
{
    public abstract class PrimeSequence<T> : IEnumerable<T>
    {
        public IEnumerator<T> GetEnumerator()
        {
            return Sequence.GetEnumerator();
        }

        protected abstract IEnumerable<T> Sequence { get; }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }

    public class IntPrimeSequence : PrimeSequence<int>
    {
        private readonly IEnumerable<int> sequence;

        public IntPrimeSequence()
        {
            sequence = 2.ToMax().Where(t => t.IsPrime());
        }

        protected override IEnumerable<int> Sequence { get { return sequence;} }
    }

    public class LongPrimeSequence : PrimeSequence<long>
    {
        private readonly IEnumerable<long> sequence;

        public LongPrimeSequence()
        {
            sequence = LongSequence.NewSequence().Start(2).Where(t => t.IsPrime());
        }

        protected override IEnumerable<long> Sequence { get { return sequence;} }
    }
}